{include file="public/header"}

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form action="" method="post" class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span> 账号
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="username" name="username" value="{$admin.username}" required=""
                            lay-verify="required" autocomplete="off" class="layui-input" readonly disabled>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span> 备注
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="nickname" value="{$admin.nickname|default=''}" required=""
                            lay-verify="required" autocomplete="off" class="layui-input" readonly disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span> 发帖备注
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="poster" name="poster" value="{$admin.poster|default=''}" required=""
                            lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="cover" class="layui-form-label">
                        <span class="x-red">*</span>头像</label>
                    <div class="layui-input-inline">
                        <button type="button" class="layui-btn" id="test1">上传头像</button>
                        <div class="layui-upload-list">
                            <input type="hidden" value="{$admin.images|default=''}" name="images" id="covers">
                            <img class="layui-upload-img" id="demo1" src="{$admin.images|default=''}"
                                style="width: 200px;height: auto;">
                            <p id="demoText">683px * 286 px</p>
                        </div>
                    </div>
                </div>
                <!-- <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>选择省</label>
                    <div class="layui-input-inline">
                        <select name="data[province]" data-area="" lay-filter="province" disabled>
                            <option value="">选择省</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>选择市</label>
                    <div class="layui-input-inline">
                        <select name="data[city]" data-area="" lay-filter="city" disabled>
                            <option value="">选择市</option>
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span> 如需更改，请联系上级合伙人
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        选择区</label>
                    <div class="layui-input-inline">
                        <select name="data[area]" data-area="" lay-filter="area" disabled>
                            <option value="">选择区</option>
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span> 如需更改，请联系上级合伙人
                    </div>
                </div> -->

                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span> 密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="password" name="password" value="" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span> 确认密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="passworder" name="passworder" value="" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
                </div>
            </form>
        </div>
    </div>
    {include file="public/footer"}

    <script>
        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;
            //图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: '/Base/upload_img'
                , accept: 'images'
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $('#covers').val(res.data.src);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        });
        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;
            //渲染省份
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { level: 1, adminid: "{$admin.id|default=0}" },
                success: function (res) {
                    if (res.code == 0) {
                        var str = '<option value="">请选择省份</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            if (res.type != 1) {
                                if (obj.area_code == res.province) {
                                    str += '" selected>' + obj.name;
                                } else {
                                    str += '" disabled>' + obj.name;
                                }
                            } else {
                                if (obj.area_code == res.province) {
                                    str += '" selected>' + obj.name;
                                } else {
                                    str += '">' + obj.name;
                                }
                            }
                            str += '</option>';
                        });
                        $('select[name="data[province]"]').html(str);
                        form.render();
                    }
                }
            });
            //选软城市
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { level: 2, adminid: "{$admin.id|default=0}" },
                success: function (res) {
                    if (res.code == 0) {
                        var str = '<option value="">请选择城市</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            if (res.type != 1) {
                                if (obj.area_code == res.city) {
                                    str += '" selected>' + obj.name;
                                } else {
                                    str += '" disabled>' + obj.name;
                                }
                            } else {
                                if (obj.area_code == res.city) {
                                    str += '" selected>' + obj.name;
                                } else {
                                    str += '">' + obj.name;
                                }
                            }
                            str += '</option>';
                        });
                        $('select[name="data[city]"]').html(str);
                        form.render();
                    }
                }
            });
            //选软区域
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { level: 3, adminid: "{$admin.id|default=0}" },
                success: function (res) {
                    if (res.code == 0) {
                        var str = '<option value="">请选择区域</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            if (res.type == 3) {
                                if (obj.area_code == res.area && "{$admin.id|default=0}" > 0) {
                                    str += '" selected>' + obj.name;
                                } else {
                                    str += '" disabled>' + obj.name;
                                }
                            } else {
                                if (obj.area_code == res.area && "{$admin.id|default=0}" > 0) {
                                    str += '" selected>' + obj.name;
                                } else {
                                    str += '">' + obj.name;
                                }
                            }
                            str += '</option>';
                        });
                        $('select[name="data[area]"]').html(str);
                        form.render();
                    }
                }
            });
            //监听省份选择市区
            form.on('select(province)', function (data) {
                $.ajax({
                    type: 'get',
                    url: '/base/getarea',
                    data: { id: data.value, level: 2 },
                    success: function (res) {
                        if (res.code == 0 && data.value > 0) {
                            var str = '<option value="">请选择城市</option>';
                            $.each(res.data, function (i, obj) {
                                str += '<option value="' + obj.area_code;
                                str += '">' + obj.name;
                                str += '</option>';
                            });
                            $('select[name="data[city]"]').html(str);
                            form.render();
                        }
                    }
                });
                return false;
            });

            //监听市区选择地区
            form.on('select(city)', function (data) {
                $.ajax({
                    type: 'get',
                    url: '/base/getarea',
                    data: { id: data.value, level: 3 },
                    success: function (res) {
                        if (res.code == 0 && data.value > 0) {
                            var str = '<option value="">请选择县/区域</option>';
                            $.each(res.data, function (i, obj) {
                                str += '<option value="' + obj.area_code;
                                str += '">' + obj.name;
                                str += '</option>';
                            });
                            $('select[name="data[area]"]').html(str);
                            form.render();
                        }
                    }
                });
                return false;
            });
            //监听提交
            form.on('submit(add)', function (data) {
                console.log(data);
                //发异步，把数据提交给php
                $.ajax({
                    'type': 'post',
                    data: data.field,
                    success: function (res) {
                        console.log(res);
                        if (res.status == 0) {
                            layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
                return false;
            });

        });
    </script>